package com.woniu.qqmaster.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.woniu.qqmaster.entity.*;
import org.apache.ibatis.annotations.*;
import org.springframework.cache.annotation.Cacheable;

import java.util.List;

/**
 * @Author dlb
 * @Date 2022/12/27 16:30
 */
@Mapper
public interface QqUserMapper extends BaseMapper {
//    String findUserSql = "        select b.QQID,b.NickName,b.Sex,b.Age,b.Province,b.City,b.Address,b.Phone,\n" +
//            "               u.`PassWord`,u.lastLogTime,u.`OnLine`,u.`Level`,\n" +
//            "               r.RelationQQID,r.RelationStatus\n" +
//            "        from relation r inner join baseinfo b\n" +
//            "        on(b.qqid = r.RelationQQID) inner join qquser u on (u.qqid = r.RelationQQID)\n";

    String findUserSql = "select u.QQID as uqqid,u.`PassWord`,u.lastLogTime,u.`OnLine`,u.`Level`,r.QQID as rqqid,r.RelationQQID,r.RelationStatus,bi.QQID as biqqid,bi.NickName,bi.Sex,bi.Age,bi.Province,bi.City,bi.Address,bi.Phone \n" +
            "from qquser as u INNER JOIN relation as r on u.QQID = r.RelationQQID \n" +
            "INNER JOIN baseinfo as bi on bi.QQID = r.RelationQQID ";

    @Select(" select * from qquser where QQID = #{uname} and PassWord = #{upwd} ")
    Qquser login(@Param("uname") String uname,@Param("upwd") String upwd);

    @Select(findUserSql+" ${ew.customSqlSegment}")
    @Results({
            @Result(column = "uqqid",property = "user.qqid"),
            @Result(column = "PassWord",property = "user.passWord"),
            @Result(column = "lastLogTime",property = "user.lastLogTime"),
            @Result(column = "OnLine",property = "user.onLine"),
            @Result(column = "Level",property = "user.level"),
            @Result(column = "rqqid",property = "rel.qqid"),
            @Result(column = "RelationQQID",property = "rel.relationQqid"),
            @Result(column = "RelationStatus",property = "rel.relationStatus"),
            @Result(column = "NickName",property = "info.nickName"),
            @Result(column = "biqqid",property = "info.qqid"),
            @Result(column = "Sex",property = "info.sex"),
            @Result(column = "Sex",property = "info.sex"),
            @Result(column = "Age",property = "info.age"),
            @Result(column = "Province",property = "info.province"),
            @Result(column = "City",property = "info.city"),
            @Result(column = "Address",property = "info.address"),
            @Result(column = "Phone",property = "info.phone"),
    }
    )
    IPage<QQUserBO> getInfoByUserId(IPage<QQUserBO> page, @Param("ew") Wrapper<QQUserBO> wrapper);

}
